package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Vendertransaction;
import com.restaurant.service.VendertransactionService;

public class VendertransactionServiceImpl implements VendertransactionService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Vendertransaction addOrModify( Vendertransaction objVendertransaction ) {
       return ( Vendertransaction ) hibernateTemplate.merge( objVendertransaction );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Vendertransaction deleteRecord( Vendertransaction objVendertransaction ) {
       hibernateTemplate.delete( objVendertransaction );
       return objVendertransaction;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Vendertransaction modifyRecord( Vendertransaction objVendertransaction ) {
       return ( Vendertransaction ) hibernateTemplate.merge( objVendertransaction );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Vendertransaction> loadAll() {
       return (List<Vendertransaction>)hibernateTemplate.findByNamedQuery( "Vendertransaction.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Vendertransaction loadByPrimaryKey( Long primaryKey ) {
       return (Vendertransaction) hibernateTemplate.get( Vendertransaction.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Vendertransaction deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Vendertransaction> loadByHql(String query) {
       return ( List<Vendertransaction> ) hibernateTemplate.find( query );
   }
}